<?php
/**
 * 获取品鉴活动对应的商品数据
 */
namespace app\common\model;

use think\Db;
use think\Model;

/**
 * ============================================================================
 * 佳皿一站式,酒水服务类综合平台
 * ============================================================================
 * 版权所有 2019-2028 成都佳皿商贸有限公司，并保留所有权利。
 * 网站地址: http://www.91buys.com
 * ----------------------------------------------------------------------------
 * 最终解释权,归属于成都佳皿商贸有限公司。
 * 佳皿一站式服务虽好,别忘常来。
 * ============================================================================
 * 数据层模型
 */
class Tastinggoods extends Model
{
    protected $table = 'tasting_goods';
    public $page_info;
    /**
     * 获取单条品鉴商品信息
     * @param array $condition  查询条件
     * @param string $field     查询字段
     */
    public function getItemByCondition($condition = [],$field = '*')
    {
        return  Db::name($this->table)->field($field)->where($condition)->find();
    }
    /**
     * 添加
     * @author csdeshang
     * @param array $data
     * @return bool
     */
    public function addtasting_goods($data){
        return db('tasting_goods')->insertGetId($data);
    }

    /**
     * 根据条件更新
     * @author csdeshang
     * @param array $data 更新内容
     * @param array $condition 更新条件
     * @return bool
     */
    public function edittasting_goods($data,$condition){
        return db('tasting_goods')->where($condition)->update($data);
    }

    /**
     * 根据条件删除
     * @author csdeshang
     * @param array $condition 条件数组
     * @return bool
     */
    public function deltasting_goods($condition){
        return db('tasting_goods')->where($condition)->delete();
    }
    /**
     * 根据条件查询活动内容信息
     * @author csdeshang
     * @param array $condition 查询条件数组
     * @param obj $page	分页页数
     * @param string $order 排序
     * @return array 二维数组
     */
    public function gettasting_goodsList($condition,$page='',$order='tasting_goods_id desc'){
        if ($page) {
            $res = db('tasting_goods')->where($condition)->order($order)->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $res;
            return $res->items();
        }else{
            return db('tasting_goods')->where($condition)->order($order)->select();
        }
    }
    /**
     * 根据条件查询活动商品内容信息
     * @author csdeshang
     * @param array $condition 查询条件数组
     * @param obj $page	分页页数
     * @param string $order 排序
     * @return array 二维数组
     */
    public function getGoodsJoinList($condition,$page='',$order=''){
        $field	= 'tasting_goods.*,goods.*';
        $res=db('tasting_goods')->alias('tasting_goods')->join('__GOODS__ goods','tasting_goods.goods_id=goods.goods_id')->field($field)->where($condition)->order($order)->paginate($page,false,['query' => request()->param()]);
        $this->page_info=$res;
        return $res->items();
    }
    /**
     * 查询活动商品信息
     * @author csdeshang
     * @param array $condition 查询条件数组
     * @return array 二维数组
     */
    public function gettasting_goodsAndGoodsList($condition){
        $field	= 'tasting_goods.tasting_goods_sort,goods.goods_id,goods.store_id,goods.goods_name,goods.goods_price,goods.goods_image';
        $res= db('tasting_goods')->alias('tasting_goods')->join('__GOODS__ goods','tasting_goods.item_id=goods.goods_id')->field($field)->where($condition)->select();
        return $res;
    }
    /**
     * 查询多条记录
     * @param $condition
     * @param string $field
     * @return mixed
     */
    public function getSelectItems($condition ,$field = '*')
    {
        return  db('tasting_goods')->field($field)->where($condition)->select();
    }
}
